package com.epam.airlines;

import java.io.Serializable;
import java.util.Random;

public class Helicopter extends Aircraft implements Serializable {

	private static final long serialVersionUID = 1L;
	private Engine engine;
	private int tankVolume;
	private int consumed;

	public Helicopter(String name, int numPass, float tonnage, int distance,
			int consumption, String id, Engine engine, int tankVolume) {
		super(name, numPass, tonnage, distance, consumption, id);
		this.engine = engine;
		this.tankVolume = tankVolume;
	}

	@Override
	public String toString() {
		return "The helicopter " + getName() + ", id: " + getId()
				+ ", engine: " + engine + ", tank: " + tankVolume
				+ " l, consumes " + getConsumption() + " kg/h, "
				+ getDistance() + " km, " + getFlyingHoursTotal()
				+ " flying h, " + getNumPass() + " people, " + getTonnage()
				+ " t, consumed "+consumed+" l";
	}

	@Override
	public void makeFlight() {
		Random rand = new Random();
		super.makeFlight();
		consumed+=rand.nextInt(150);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + consumed;
		result = prime * result + ((engine == null) ? 0 : engine.hashCode());
		result = prime * result + tankVolume;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Helicopter other = (Helicopter) obj;
		if (consumed != other.consumed)
			return false;
		if (engine != other.engine)
			return false;
		if (tankVolume != other.tankVolume)
			return false;
		return true;
	}

}
